<?php
	include('submitEdit.php');
	$dom;
	if (isset($_POST['curCon']))	
		$concept = $_POST['curCon'];
?>

<article id="Domain">
	<div class="topArticle">
		<h2>Domaine</h2>
	</div>
	<div class="corpsArticle">
		<form id="domainForm" method="post" action="index.php?page=formEDIT">
			
			<label for="selectDom">Nom Domaine</label>
			<select id="selectDom" name="domain">
			<?php
				if (isset($_SESSION['theso']))
				{
					$result = pg_query($db, "SELECT * FROM GET_DOMAINS('".$_SESSION['theso']."');");
				
					while ($data = pg_fetch_object($result)) 
					{
							echo "<option value='" . $data->get_domains ."'>".$data->get_domains."</option>";
					}
				}
			?>
               				
      			 </select>
			
			<label for="inputNom">Nouveau Nom</label>
			<input id="inputNom" name="nomDo" type="text" />
				
			<br \>
			<label for="inputDesc">Nouvelle Description</label>
			<input id="inputDesc" name="descDo"type="text" />
			<br \>
			<input name="whichForm" value="domain" type="hidden" />
			<input id="sendDomainButton" type="submit" value="Mettre à jour">
			
		</form>
	</div>
</article>
<article id="Concept">
	<div class="topArticle">
		<h2>Concept</h2>
	</div>
	<div class="corpsArticle">
		<form id="conceptForm" method="post" action="index.php?page=formEDIT">
			
			<label for="selectDomain">Domaine</label>
			<select id="selectDomain" name="Domain" onchange="changeDomSel()">
			<?php
				if (isset($_SESSION['theso']))
				{
				$result = pg_query($db, "SELECT * FROM GET_DOMAINS('".$_SESSION['theso']."');");
				
				$fin = false;
				while ($data = pg_fetch_object($result)) 
				{
					if (!isset($_POST['curDom']) && $fin == false)
					{
						$dom = $data->get_domains;
						$fin = true;
					}
					if(isset($_POST['curDom']) && $_POST['curDom'] == $data->get_domains)
					{
 					 	echo "<option selected='true' value='" . $data->get_domains ."'>".$data->get_domains."</option>";
						$dom = $data->get_domains;
					}
					else
					{
						echo "<option value='" . $data->get_domains ."'>".$data->get_domains."</option>";
					}
				}
				}
			?>
               				
      			 </select>
			
			<label for="inputTV">Terme Vedette</label>
			<select id="inputTV" name="termeV" onchange="changeTVSel()">
		<?php
			if(isset($dom))
			{
				$result = pg_query($db, "SELECT * FROM GET_CONCEPTS('".$dom."');");
				if (!$result) 
				{
				  	echo "An error occured.\n";
				  	exit;
				}
				$fin = false;
				while ($data = pg_fetch_object($result)) 
				{
					if ((!isset($_POST['curCon']) || $_POST['curCon'] == 'change') && $fin == false)
					{
						$concept = $data->get_concepts;
						$fin = true;
					}
					if(isset($_POST['curCon']) && $_POST['curCon'] == $data->get_concepts)
					{
 					 	echo "<option selected='true' value='" . $data->get_concepts ."'>".$data->get_concepts."</option>";
						$concept = $data->get_concepts;
					}
					else
					{
						echo "<option value='" . $data->get_concepts ."'>".$data->get_concepts."</option>";
					}
				}
			}
		?>	
      			</select>
			
			<label for="inputNewTV">Nouveau Nom</label>
			<input id="inputNewTV" name="newTermeV" type="text" />
			<input id="sendConceptButton"  name="maj" value="Mettre à jour" type="submit" onclick="subT()">
      			 <br />
      			 <br />
			<table align="center">
				<tr> 
					<th><label for="selectTS">TS</label> </th>
					<th><label for="inputTG">TG</label></th>
					<th><label for="inputT">T</label></th>
				</tr>
				<tr> 
					<td> <select id="selectTS" name="TermeS">
						<?php
							if(isset($dom))
							{
								$result = pg_query($db, "SELECT * FROM GET_CONCEPTS('".$dom."');");
								if (!$result) 
								{
				  					echo "An error occured.\n";
				  					exit;
								}
								while ($data = pg_fetch_object($result)) 
								{
										echo "<option value='" . $data->get_concepts ."'>".$data->get_concepts."</option>";
								}
							}
						?>	
      					</select>
      						<input id="addTS" type="submit" name="addts" value="+" onclick="subT()"/>
						<input id="addTS" type="submit" name="addts" value="-" onclick="subT()"/>
					</td>
					<td>
					<select id="selectTG" name="TermeG">
               					<?php
							if(isset($dom))
							{
								$result = pg_query($db, "SELECT * FROM GET_CONCEPTS('".$dom."');");
								if (!$result) 
								{
				  					echo "An error occured.\n";
				  					exit;
								}
								while ($data = pg_fetch_object($result)) 
								{
										echo "<option value='" . $data->get_concepts ."'>".$data->get_concepts."</option>";
								}
							}
						?>
      					</select>
					<input id="addTG" type="Submit" name="addtg" value="+" onclick="subT()"/>
					<input id="addTG" type="Submit" name="addtg" value="-" onclick="subT()"/>
					</td>
					<td>
						<input id="inputT" name="Terme" type="text" />
						<input id="addT" type="submit" name="addt" value="+" onclick="subT()" >
						<input id="addT" type="submit" name="addt" value="-" onclick="subT()" >
					</td>
				</tr>

				<tr>
					<td>
						<select id="listTS" name="listTS" MULTIPLE class="listTerme">
						<?php
						if(isset($concept))
							{
								$result = pg_query($db, "SELECT * FROM GET_TS('".$concept."');");
								if (!$result) 
								{
				  					echo "An error occured.\n";
				  					exit;
								}
								while ($data = pg_fetch_object($result)) 
								{
										echo "<option value='" . $data->get_ts ."'>".$data->get_ts."</option>";
								}
							}
						?>
						</select>
					</td>
					<td>
						<select id="listTG" name="listTG" MULTIPLE class="listTerme">
						<?php
						if(isset($concept))
							{
								$result = pg_query($db, "SELECT * FROM GET_TG('".$concept."');");
								if (!$result) 
								{
				  					echo "An error occured.\n";
				  					exit;
								}
								while ($data = pg_fetch_object($result)) 
								{
										echo "<option value='" . $data->get_tg ."'>".$data->get_tg."</option>";
								}
							}
						?>
						</select>
					</td>
					<td>
								
						<select id="listT" name="listT" MULTIPLE class="listTerme">
						<?php
						if(isset($concept))
							{
								$result = pg_query($db, "SELECT * FROM GET_TERMNVDTS('".$concept."');");
								if (!$result) 
								{
				  					echo "An error occured.\n";
				  					exit;
								}
								while ($data = pg_fetch_object($result)) 
								{
										echo "<option value='" . $data->get_termnvdts ."'>".$data->get_termnvdts."</option>";
								}
							}
						?>
						</select>
					</td>
				</tr>
			</table> 
			<input name="whichForm" value="concept" type="hidden" />
			<input id="curDom" name="curDom"  type="hidden" />
			<input id="curCon" name="curCon"  type="hidden" />
		</form>
		
		
				
	</div>
</article>
<article id="Association">
	<div class="topArticle">
		<h2>Association</h2>
	</div>
	<div class="corpsArticle">
		<form id="AssForm" method="post" action="index.php?page=formEDIT">
					
				
			<select id="assoc" name="assoc">
			<?php
				$qc1 = pg_query($db, "SELECT * FROM Concepts order by nom");
				if (!$qc1) 
				{
  					echo "An error occured.\n";
  					exit;
				}
				while ($c1 = pg_fetch_object($qc1)) 
				{
					$q1 = pg_query($db, "SELECT * FROM GET_ASSOCIATIONS1('".$c1->nom."') AS(concept_oid OID,association TEXT,concept TEXT, Reflex BOOLEAN);");
					while ($c = pg_fetch_object($q1)) 
					{
						echo "<option value='". $c->association ."'>".$c1->nom." ". $c->association ." ".$c->concept."</option>";
					}
				}
			?>
      			 </select>
			<label for="newName">Nouveau nom association</label>
			<input type="text" name="newName" id="newName" />
			<input name="whichForm" value="assoc" type="hidden" />
			<input id="sendDomainButton" type="submit">
		</form>
	</div>
</article>
